import { BASE_URL } from './BASE_URL.js'

/**
 * @description  跳转指定页面
 * @param url   需要跳转的路径
 * @param type  跳转类型 默认navigateTo
 */
export const jumpPage =  (url,type) => {
	// console.log('url',url);
	if (type) {
		uni.switchTab({
			url
		})
	}else {
		uni.navigateTo({
			url
		})
	}
}

/**
 * @params {e} 文件对象
*/ 
export const upFile = async (e)=>{
	return new Promise( async (resolve,reject) => {  
	        uni.uploadFile({    
				url: BASE_URL+'/api/upload', 
				filePath: e,
				name: 'img',  
	            success: (res) => {    
					console.log('HOOKS',res);
	                resolve(JSON.parse(res.data))  
	            },    
	            fail: (err) => {    
	                reject  
	            }    
	        })    
	    })  
}


/**
 * @params {text} 需要复制的文本
*/ 

export const copyText = (text) =>{
	uni.setClipboardData({
	  data: text,
	  success: function() {
	   uni.showToast({
	   	title:"复制成功"
	   })
	  }
	})
}



export const  timestampToTime = (timestamp)=> {
  if (!timestamp) return '无'
  var date = new Date(timestamp);
  var Y = date.getFullYear() + "-";
  var M =
    (date.getMonth() + 1 < 10
      ? "0" + (date.getMonth() + 1)
      : date.getMonth() + 1) + "-";
  var D = (date.getDate() < 10 ? "0" + date.getDate() : date.getDate()) + " ";
  return Y + M + D 
}






/**
* @description  对象批量赋值
* @params  mineObj 需要赋值的对象
* @params  targeObj 目标对象
*/

  export const objectAssign =  (mineObj,targeObj)=>{
    let res = new Object
    let mineKey =  Object.keys(mineObj)
    let targetKey =  Object.keys(targeObj)
    targetKey.forEach((item)=>{
        mineKey.forEach(it=>{
          if (it == item){
            mineObj[it] = targeObj[item]
          }
        })
      })
      res = mineObj
     return res
}